package org.apache.spark.sql.catalyst.rule

import org.apache.spark.internal.Logging
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.catalyst.expressions.{Literal, Multiply}
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.catalyst.rules.Rule

/**
 * 自定义优化规则, spark-2.4.4 版本
 * @param sc
 */
case class MyRule(sc: SparkSession) extends Rule[LogicalPlan] with Logging {
  override def apply(plan: LogicalPlan): LogicalPlan = {
    /*plan transformAllExpressions {
      case Multiply(left, right) if right.isInstanceOf[Literal] && right.asInstanceOf[Literal].value.asInstanceOf[Double] == 1.0 => {
        println("优化规则生效")
        left
      }
    }*/
    plan
  }
}
object MutiplyOptimizationRule extends Rule[LogicalPlan] with Logging {
  override def apply(plan: LogicalPlan): LogicalPlan = {
    /*plan transformAllExpressions {
      case Multiply(left, right) if right.isInstanceOf[Literal] && right.asInstanceOf[Literal].value.asInstanceOf[Double] == 1.0 => {
        println("优化规则生效")
        left
      }
    }*/
    plan
  }
}
